#include "cmsis_os.h" 
#include "stm32f4xx.h" 
#include "GPIO_STM32F4xx.h"             // Keil::Device:GPIO
#include <string.h>                     /* String and memory functions        */
#include "Driver_MCI.h"                 // ::Drivers:MCI
#include "keyprocess.h"
#include "settings.h"
#include "alarm.h"
#include "measurement/measurement.h"

SETTINGS settings;
DEVICE_STATE deviceState;
enum KeyStroke key;

static void init_pins (void) {
	GPIO_PortClock(GPIOA, ENABLE);
	GPIO_PortClock(GPIOB, ENABLE);
//	GPIO_PinConfigure(GPIOA,12,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_100MHz,GPIO_NO_PULL_UP_DOWN);
	GPIO_PinConfigure(GPIOB,14,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_100MHz,GPIO_NO_PULL_UP_DOWN);
	GPIO_PinConfigure(GPIOB,15,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_100MHz,GPIO_NO_PULL_UP_DOWN);	
	GPIO_PinWrite(GPIOB,14,1);
	osDelay(100);
	GPIO_PinWrite(GPIOB,15,1);
	osDelay(2000);
}


int main (void) {
	SystemInit();
	initDisplay();
	init_pins();       // инициализация пинов диода и карты памяти	
	LoadSettings(&settings, SETTINGS_FILENAME);	// загрузка настроек
	initKeyboard();	
  selectDisplay(START_SCREEN);
	osDelay(1000);	
	measureInit();	
	sendStandBy(settings.standByTime, OFF_DISPLAY_MODE);
	setParameter(FILTER, settings.firFreq);
	setParameter(PERIOD_MEASURE, settings.measureTime);
	selectDisplay(MAIN_SCREEN);
	deviceState = Screen1_Init_State;
	
	setDateTime(2000,03,21,15,00);
		
	
	
	
	for (;;) 
	{		
		key=waitKeyStroke();
		deviceState = ProcessKey(key,deviceState);
		if (deviceState == Exit) {			
			break;
		}
	}	
}
